package com.wjjun.base.ui.window

import androidx.databinding.ViewDataBinding
import com.wjjun.base.ui.window.BaseBottomDialog
import com.wjjun.base.ui.activity.BaseActivity
import com.wjjun.base.ui.helper.RefreshRecycleViewHelper
import com.wjjun.base.ui.listener.IItemViewListener
import com.wjjun.base.ui.viewmodel.BaseItemViewModel
import com.wjjun.base.ui.viewmodel.BaseWindowViewModel

/**
 * 底部显示的弹窗
 *
 * author : wangjunjun
 * date   : 2022/6/8
 * desc   :
 */
abstract class BaseListBottomDialog<VM : BaseWindowViewModel, VD : ViewDataBinding>(context: BaseActivity) :
    BaseBottomDialog<VM, VD>(context), RefreshRecycleViewHelper.DataProvide, IItemViewListener {

    protected val mRecycleViewHelper = RefreshRecycleViewHelper()

    override fun buildViewBinding() {
        super.buildViewBinding()
        mRecycleViewHelper.bindViewDataBinding(viewDataBinding)
    }

    override fun initViews() {
        super.initViews()
        mRecycleViewHelper.dataProvide = this
        mRecycleViewHelper.onItemClickListener = this
    }

    override fun initContent() {
        mRecycleViewHelper.refreshData()
    }

    fun setEmptyStyle(icon: Int, msg: String) {
        mRecycleViewHelper.setEmpty(icon, msg)
    }

    fun setData(data: List<BaseItemViewModel<*>>, pageNum: Int = 1) {
        mRecycleViewHelper.setData(data, pageNum)
    }

    fun addData(data: List<BaseItemViewModel<*>>) {
        mRecycleViewHelper.addData(data)
    }

    fun addItem(index: Int, itemViewModel: BaseItemViewModel<*>) {
        mRecycleViewHelper.addItem(index, itemViewModel)
    }

    fun addItem(itemViewModel: BaseItemViewModel<*>) {
        mRecycleViewHelper.addItem(itemViewModel)
    }

    fun removeAt(index: Int) {
        mRecycleViewHelper.removeAt(index)
    }

    fun removeItem(itemViewModel: BaseItemViewModel<*>) {
        mRecycleViewHelper.removeItem(itemViewModel)
    }

    fun removeList(list: Collection<BaseItemViewModel<*>>) {
        mRecycleViewHelper.removeList(list)
    }

    fun clearData() {
        mRecycleViewHelper.clearData()
    }

    /**
     * 设置是否可以刷新
     */
    fun setRefreshEnable(enable: Boolean) {
        mRecycleViewHelper.setRefreshEnable(enable)
    }

    /**
     * 设置是否自动加载更多
     */
    fun setLoadMoreEnable(enable: Boolean) {
        mRecycleViewHelper.setLoadMoreEnable(enable)
    }

    /**
     * 设置列表为空时的显示样式
     */
    fun setListEmpty(icon: Int, msg: String) {
        mRecycleViewHelper.setEmpty(icon, msg)
    }
}